import React from 'react';
import Bread from '../../component/TableContent/VipBread';
import { Breadcrumb,Input ,Radio,Button,message } from 'antd'
import { withRouter } from 'react-router-dom'
import axios from '../../utils/http'
import './sign.css'
//签到管理

@withRouter
class SignManage extends React.Component {
  constructor() {
    super()
    this.state = {
      value: '',
      value1: '',
      returnobj: {
        incInte: '',//签到积分
        signStatu:'',//是否递增
        signInte:'',//每天递增积分
        inteMax:'',//最大积分
        signlogStatus:'',//是否保存签到日志
        logDay:'',//保存天数
      }
    }
  }
  qiehuan = () => {
    this.props.history.push('/Home/huiYuan/SignManage')
  }
  qiehuan1 = () => {
    this.props.history.push('/Home/huiYuan/SignLog')
  }
  onChange = val => {
    return e => {
      let returnobj = this.state.returnobj;
      returnobj[val] = e.target.value
      if (val === 'signStatu') {
        this.setState(
          {
            value: e.target.value,
            returnobj
          })
      } else {
        this.setState(
          {
            value1: e.target.value,
            returnobj
          })
      }
    }
  };
  setval = val => {
    return e => {
      let returnobj = this.state.returnobj;
      returnobj[val] = e.target.value
      this.setState({
        returnobj
      })
    }
    
  }
  makesure = () => {
    axios({
      url: '/member/updateSignlog',
      method: 'post',
      data:this.state.returnobj
    }).then(data => {
      if (data.data.code === 200) 
        message.success('修改成功')
      else message.error('修改失败')
    })
  }
  render() {
  return (
    <div className='signmanage'>
      <Bread mianbao='签到管理'></Bread>
      <Breadcrumb>
        <Breadcrumb.Item onClick={this.qiehuan}>签到管理</Breadcrumb.Item>
        <Breadcrumb.Item onClick={this.qiehuan1}>签到日志</Breadcrumb.Item>
      </Breadcrumb>
      <div className='wrapper'> 
        <div className='clear'>
          <span className='rignh'>签到积分</span> <Input style={{ width: '10%' }} defaultValue='' onChange={this.setval('incInte')}></Input>
          <hr />
          <div>
            <div style={ {float:'left',lineHeight:'10rem'}}>是否递增模式</div>
            <div style={{ marginLeft: '9rem',float:'left' }}>
            <Radio.Group onChange={this.onChange('signStatu')} value={this.state.value}>
              <Radio value={1} style={ {color:'#e2e2e2'}} >是</Radio>
              <Radio value={0} style={{ color: '#e2e2e2' }}>否</Radio>
            </Radio.Group> <br />
              要开启递增模式，则需要同时设置每天递增积分、赠送积分的最大值。<br />
              递增模式下，连续签到所获得积分为：签到积分+已签到天数*每天递增积分。<br/>
              例：签到积分：5，每天递增积分：1，那么第一天签到就是：5+0*1=5，第二天就是5+1*1=6，以此类推。<br/>
              当达到赠送积分最大值后，则不管再连续签到几天，都只赠送积分最大值对应的积分。</div>
            </div>
        </div>
        <hr />
        <span className='rignh'>每天递增积分</span> <Input style={{ width: '10%'}} onChange={this.setval('signInte')}></Input>
        <hr />
        <span  className='rignh'>赠送积分最大值</span> <Input style={{ width: '10%'  }} onChange={this.setval('inteMax')}></Input>
        <hr />
        <span  className='rignh'>是否保存签到日志</span>
        <Radio.Group onChange={this.onChange('signlogStatus')} value={this.state.value1} >
          <Radio value={1} style={ {color:'#e2e2e2'}} >是</Radio>
          <Radio value={0} style={{ color: '#e2e2e2' }}>否</Radio>
        </Radio.Group> <br />
        <hr />
        <span  className='rignh'>签到日志保存天数</span><Input style={{ width: '10%' }} onChange={this.setval('logDay')}></Input>为每个用户保存签到日志多少天，0表示不限制。
        <hr />
      </div>
      <Button className='surename' onClick={ this.makesure}>确定</Button>
    </div>
  );
}
}
export default SignManage;